// pages/setting/setting.js
const app = getApp()
import { ble_send_date} from "../../utils/util.js";
Page({

  /**
   * 页面的初始数据
   */
  data: {
    checked: true,
    currentValue:50,
    flaValue:0,
    fla_2Value:0,
    fla_3Value:0,
    fla_4Value:0,
    fla_5Value:0,
  },

  onChange_led_state({ detail }) {//开关灯
    console.log(detail);
    let { bleStore } = app.store.getState();
    bleStore[2] = detail ? 1 : 0;
    app.store.setState({ bleStore});
    ble_send_date(8);
  },
  
  onDrag_Pwm(event) { //亮度调节
    if (this.data.flaValue != event.detail.value) {
      this.data.flaValue = event.detail.value;
    }else{
      return 0;
    }
    this.setData({flaValue : this.data.flaValue})
    let { bleStore } = app.store.getState();
    bleStore[3] = this.data.flaValue;
    app.store.setState({ bleStore});
    ble_send_date(9);
  },

  onDrag_Pwm2(event) { //亮度调节2
    if (this.data.flaValue != event.detail) {
      this.data.flaValue = event.detail;
    }else{
      return 0;
    }
    this.setData({flaValue : this.data.flaValue})
    let { bleStore } = app.store.getState();
    bleStore[3] = this.data.flaValue;
    app.store.setState({ bleStore});
    
    ble_send_date(9);
  },
  
  onChange_long_off({ detail }) {//延迟关灯
    let { bleStore } = app.store.getState();
    bleStore[4] = detail ? 1 : 0;
    app.store.setState({ bleStore});
    ble_send_date(10);
  },

  onDrag_off_timer(event) {//延迟关灯调节
    if (this.data.fla_2Value != event.detail.value) {
      this.data.fla_2Value = event.detail.value;
    }else{
      return 0;
    }
    this.setData({fla_2Value : this.data.fla_2Value})
    let { bleStore } = app.store.getState();
    bleStore[5] = event.detail.value;
    app.store.setState({ bleStore});
    //ble_send_date(11);
  },

  onDrag_off_timer2(event) {//延迟关灯调节
    let { bleStore } = app.store.getState();
    bleStore[5] = event.detail;
    app.store.setState({ bleStore});
    ble_send_date(11);
  },

  onChange_am_pm({ detail }) {//是否12小时制度
    let { bleStore } = app.store.getState();
    bleStore[6] = detail ? 1 : 0;
    app.store.setState({ bleStore});
    ble_send_date(12);
  },

  onChange_timek({ detail }) {//是否整时报点
    let { bleStore } = app.store.getState();
    bleStore[7] = detail ? 1 : 0;
    app.store.setState({ bleStore});
    ble_send_date(13);
  },
  
  onChange_units(e){//温度单位修改
    let { bleStore } = app.store.getState();
    bleStore[1] ^= 1;
    app.store.setState({ bleStore});
    ble_send_date(14);
  },


  onDrag_vol_lever(event) {//音量调节
    if (this.data.fla_3Value != event.detail.value) {
      this.data.fla_3Value = event.detail.value;
    }else{
      return 0;
    }
    this.setData({fla_3Value : this.data.fla_3Value})
    let { bleStore } = app.store.getState();
    bleStore[8] = event.detail.value;
    app.store.setState({ bleStore});
    //ble_send_date(15);
  },

  onDrag_vol_leve2(event) {//音量调节
    let { bleStore } = app.store.getState();
    bleStore[8] = event.detail;
    app.store.setState({ bleStore});
    ble_send_date(15);
  },

  onChange_ring_strong({ detail }) {//铃声渐强
    let { bleStore } = app.store.getState();
    bleStore[9] = detail ? 1 : 0;
    app.store.setState({ bleStore});
    ble_send_date(16);
  },

  Change_do_switch({ detail }) {//倒计时开关
    let { bleStore } = app.store.getState();
    if (bleStore[12]) {
      wx.showToast({
        title: '请先关闭正计时',
        icon: 'none'
      });
      return
    }
    bleStore[10] = detail ? 1 : 0;
    app.store.setState({ bleStore});
    ble_send_date(17);
  },

  change_time_down(event){//倒计时时间调节
    if (this.data.fla_4Value != event.detail.value) {
      this.data.fla_4Value = event.detail.value;
    }else{
      return 0;
    }
    this.setData({fla_4Value : this.data.fla_4Value})
    let { bleStore } = app.store.getState();
    bleStore[11] = event.detail.value;
    app.store.setState({ bleStore});
    //ble_send_date(18);
  },

  change_time_down2(event){//倒计时时间调节
    let { bleStore } = app.store.getState();
    bleStore[11] = event.detail;
    app.store.setState({ bleStore});
    ble_send_date(18);
  },


  Change_up_switch({ detail }) {//正计时开关
    let { bleStore } = app.store.getState();
    if (bleStore[10]) {
      wx.showToast({
        title: '请先关闭倒计时',
        icon: 'none'
      });
      return
    }
    bleStore[12] = detail ? 1 : 0;
    app.store.setState({ bleStore});
    ble_send_date(19);
  },
  change_time_up(event){//正计时时间调节
    if (this.data.fla_5Value != event.detail.value) {
      this.data.fla_5Value = event.detail.value;
    }else{
      return 0;
    }
    this.setData({fla_5Value : this.data.fla_5Value})
    let { bleStore } = app.store.getState();
    bleStore[13] = event.detail.value;
    app.store.setState({ bleStore});
    //ble_send_date(20);
  },

  change_time_up2(event){//正计时时间调节
    let { bleStore } = app.store.getState();
    bleStore[13] = event.detail;
    app.store.setState({ bleStore});
    ble_send_date(20);
  },


  onChange_led_pwm({ detail }) {//闹钟响铃呼吸灯
    let { bleStore } = app.store.getState();
    bleStore[14] = detail ? 1 : 0;
    app.store.setState({ bleStore});
    ble_send_date(21);
  },

  
  
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {
      
  }
})